<template>
  <!-- 外部数据页面 -->
  <div class="specification">
    <div class="btn-continer">
      <el-button type="primary" @click="submitUpload" class="btn-lanse"
        ><i class="el-icon-plus el-icon--left">上传</i></el-button
      >

      <div class="btn-right">
        <el-button
          icon="el-icon-search"
          @click="getList"
          type="primary"
        ></el-button>
      </div>
      <el-input
        v-model="searchValue"
        placeholder="按文件名称检索"
        clear
        class="el-inputClass"
      ></el-input>
    </div>

    <div class="table-continer">
      <el-table
        :data="tableData"
        v-loading="loading"
        :header-cell-style="{ background: '#F0F0F6', color: '#2D3548' }"
        style="width: 100%"
      >
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="fileName" label="文件名称"> </el-table-column>
        <el-table-column prop="fileType" label="文件类型">
          <template slot-scope="scope">
            <span v-if="scope.row.fileType == 1">图片</span>
            <span v-if="scope.row.fileType == 2">视频</span>
            <span v-if="scope.row.fileType == 3">文档</span>
            <span v-if="scope.row.fileType == 4">音频</span>
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="创建人"> </el-table-column>
        <el-table-column prop="createTime" label="创建时间"> </el-table-column>
        <el-table-column prop="fileRemark" label="备注说明"> </el-table-column>

        <!-- <el-table-column label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.fileStatus == 1">待提交</span>
              <span v-if="scope.row.fileStatus == 2">待审核</span>
              <span v-if="scope.row.fileStatus == 3">退回</span>
              <span v-if="scope.row.fileStatus == 4">审核通过</span>
            </template>
          </el-table-column> -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="checkView(scope.row)" type="text" size="small"
              ><i class="el-icon-view el-icon--left"> 预览</i></el-button
            >
            <el-button @click="download(scope.row)" type="text" size="small"
              ><i class="el-icon-edit el-icon--left"> 下载</i></el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="Pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="currentPage"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
      >
      </el-pagination>
    </div>
    <checkimg
      :imgList="imgList"
      :showViewer="showViewer"
      @closeImg="closeImg"
    />
    <openPdf ref="Pdf" />
    <openMusci
      :showPlayer="showPlayer"
      :videoPlay="videoPlay"
      @musicClose="musicClose"
    />
    <el-dialog
      title="视频"
      :visible.sync="playVideo"
      width="40%"
      @close="closeMp4"
    >
      <div class="content">
        <openMp4 :video="video" :playVideo="playVideo" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import checkimg from "../components/checkImg.vue";
import openPdf from "../components/openPdf.vue";
import openMp4 from "../components/openMp4.vue";
import openMusci from "../components/openMusci.vue";
export default {
  name: "specification",
  components: { checkimg, openPdf, openMp4, openMusci },
  data() {
    return {
      showPlayer: false,
      playVideo: false,
      videoPlay: {
        title: "名称",
        artist: "音频",
        src: "",
        pic: "https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg",
      },
      video: {
        // 视频播放源
        url: "",
        // 视频海报
        // cover: 'https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png',
        muted: false, // 是否静音播放
        loop: false, // 视频是否循环播放
        preload: "auto", // 视频预加载
        poster: "", // 原生视频默认海报暂不设置
        volume: 1, // 默认音量
        autoplay: false, // 视频自动播放
      },
      fileList: [
        {
          id: 1,
          fileName: "测试PDF",
          fileUrl: "http://192.168.3.189/aaa.pdf",
        },
      ],
      url: "http://192.168.3.189/aaa.pdf", //文件地址
      currentPage: 1,
      pageSize: 10,
      totalSize: 0,
      showViewer: false,
      imgList: [],
      tableData: [],
      fileType: null, //文件类型
      loading: false,
      fileList: [],
      searchValue: "",
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      let obj = {
        fileName: this.searchValue,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };
      this.$api
        .fileList(obj)
        .then((res) => {
          // console.log(res);
          if (res.code == 200) {
            this.tableData = res.data.list;
            this.totalSize = res.data.total;
          } else {
            this.tableData = [];
            this.totalSize = 0;
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
          this.tableData = [];
          this.totalSize = 0;
        });
    },
    closeImg(flag) {
      this.showViewer = flag;
    },
    //下载
    download(row) {
      window.open(
        window.CONFIG.url +
          `/collect/fileInfo/download/${row.id}`
      );
    },
    checkView(row) {
      this.$api
        .getInfoUrl({ id: row.id })
        .then((res) => {
          if (res.data) {
            let type = row.fileType;
            if (type == 1) {
              this.imgList = [CONFIG.url + "/" + res.data];
              this.showViewer = true;
            } else if (type == 3) {
              this.$refs.Pdf.previewFn(CONFIG.url + "/" + res.data);
            } else if (type == 2) {
              this.video.url = CONFIG.url + "/" + res.data;
              this.$nextTick(() => {
                this.playVideo = true;
              });
            } else {
              this.showPlayer = false;
              let ipUrl = CONFIG.url + "/" + res.data;
              this.$nextTick(() => {
                this.videoPlay.src = ipUrl;
                this.videoPlay.title = "音频";
                this.videoPlay.artist = " ";
                this.showPlayer = true;
              });
            }
          } else {
            this.$message({
              showClose: true,
              message: res.msg,
              type: "error",
            });
          }
        })
        .catch((res) => {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error",
          });
        });
    },
    closeMp4() {
      this.$nextTick(() => {
        this.video.url = "obj";
        this.playVideo = false;
      });
    },
    musicClose(flag) {
      let ipUrl = "obj";
      this.$nextTick(() => {
        this.videoPlay.src = ipUrl;
        this.videoPlay.title = "";
        this.videoPlay.artist = "";
        this.showPlayer = flag;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
      // console.log(`当前页: ${val}`);
    },
    submitUpload() {
      this.$router.push({ path: "/specificationUp" });
    },
  },
};
</script>
<style >
._progress ._time-current,
._progress ._time-amount {
  width: 80px;
}
</style>
<style scoped lang="scss">
.specification {
  padding: 0 30px;
  overflow: hidden;
  .el-inputClass {
    float: right;
    width: 317px;
    margin-right: 10px;
  }
  .content {
    height: 520px;
  }
  .pright {
    margin-right: 10px;
  }
  .btn-continer {
    margin-top: 30px;
    margin-bottom: 20px;
    .btn-right {
      float: right;
    }
  }
  .Pagination {
    text-align: right;
    margin-top: 40px;
  }
}
</style>

